<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>登录</title>

    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/login.css" type="text/css"  rel="stylesheet">
    <script src="js/jquery-3.3.1.js"></script>
    <script src="js/getParameter.js"></script>
    
</head>

<body>
    <div class="container  text-center">
        <div id="errorMsg" class="alert alert-danger"></div>
        <form id="loginForm" action="" method="post" accept-charset="utf-8">
            <div class="input-group input-group-lg">
                <span class="input-group-addon">账号</span>
                <input type="text" name="stu_no" id="stu_no" class="form-control" placeholder="请输入账号">
            </div>
            <br>
            <div class="input-group input-group-lg">
                <span class="input-group-addon">密码</span>
                <input type="password" name="password" id="password" class="form-control" placeholder="请输入密码">
            </div>
            <br>
            <button type="button" class="btn btn-success" data-loading-text="Loading..." autocomplete="off" id="btn_sub">登 录</button>
            <a href="regist.html" class="text-right">没有账号？</a>
        </form>
    </div>
    <script>
        $(function () {
            $("#errorMsg").hide()
        });

        $("#btn_sub").click(function () {
            var $btn = $(this).button('loading')
            //发送ajax请求提交表单数据
            $.post("user/login", $("#loginForm").serialize(), function (info) {
                $btn.button('reset')
                if (info.flag) {
                    //登录成功
                    if(info.data.role == 2){
                        location.href = "index.html"
                    }else{
                        location.href = "admin-report.html"
                    }
                } else {
                    $("#errorMsg").show()
                    $("#errorMsg").html(info.errorMsg)
                }
            })
        });
        
    </script>
    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="js/bootstrap.min.js"></script>
</body>
</html>